#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
int m[7][8], ans[7][8];

void print(int a[7][8]){
    for (int r = 0; r < 7; ++r) {
        for (int c = 0; c < 8; ++c) {
            cout << setw(4) << a[r][c];
        }
        cout << "\n";
    }
    cout << "\n";
}

map<pii, int> id;
map<pii, bool> use;
void dfs(int cur){
    if(cur == 56) print(ans);
    else{
        int r = cur/8, c = cur%8;
        if(ans[r][c]) dfs(cur+1);
        else{
            int r2 = r+1, c2 = c;
            pii p = make_pair(m[r][c], m[r2][c2]);
            if(p.first > p.second) swap(p.first, p.second);
            if(!use[p]){
                use[p] = true;
                ans[r][c] = ans[r2][c2] = id[p];
                dfs(cur+1);
            }
            r2 = r, c2 = c+1;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int a; int kase = 0;
    while(cin >> a){
        for (int r = 0; r < 7; ++r) {
            for (int c = 0; c < 8; ++c) {
                int t;
                if(!c && !r) t = a;
                else cin >> t;
                m[r][c] = t;
            }
        }
        memset(ans, 0, sizeof(ans));
        int bone = 0;
        for (int i = 0; i <= 6 ; ++i) {
            for (int j = i; j <= 6 ; ++j) {
                pii t = make_pair(i, j);
                use[t] = false;
                id[t] = ++bone;
            }
        }
        cout << "Layout #" << ++kase << ":\n\n";
        print(m);
        dfs(0);

    }
    return 0;
}